package com.question.business.dict.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.question.business.dict.model.ao.DictTypeAddAO;
import com.question.business.dict.model.ao.DictTypeEnabledAO;
import com.question.business.dict.model.ao.DictTypePageAO;
import com.question.business.dict.model.ao.DictTypeUpdateAO;
import com.question.business.dict.model.vo.DictTypeAddVO;
import com.question.business.dict.model.vo.DictTypeDetailVO;
import com.question.business.dict.model.vo.DictTypeVO;
import com.question.business.dict.service.IDictTypeService;
import com.question.common.annotation.DataConvert;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;


/**
 * 字典类型接口
 *
 * @author star
 * @since 2023-09-07
 */
@RestController
@AllArgsConstructor
@RequestMapping("/dict/type")
public class DictTypeController {

    private final IDictTypeService service;


    /**
     * 字典类型分页查询
     *
     * @param ao 请求参数
     * @return Page<DictTypeVO> 响应参数
     */
    @DataConvert
    @GetMapping("/page")
    public Page<DictTypeVO> queryDictTypePage(@Validated DictTypePageAO ao) {
        return service.queryDictTypePage(ao);
    }

    /**
     * 字典类型明细查询
     *
     * @param id 字典类型ID
     * @return DictTypeDetailVO 响应参数
     */
    @DataConvert
    @GetMapping("/detail")
    public DictTypeDetailVO queryDictTypeDetail(@Validated @NotBlank(message = "删除数据不能为空") @Size(max = 20, message = "ID最大长度不能超过20") String id) {
        return service.queryDictTypeDetail(id);
    }

    /**
     * 字典类型新增数据
     *
     * @param ao 请求参数
     * @return DictTypeAddVO 响应参数
     */
    @PostMapping("/add")
    public DictTypeAddVO addDictType(@Validated @RequestBody DictTypeAddAO ao) {
        return service.addDictType(ao);
    }

    /**
     * 字典类型修改数据
     *
     * @param ao 数据
     */
    @PutMapping("/update")
    public void updateDictType(@Validated @RequestBody DictTypeUpdateAO ao) {
        service.updateDictType(ao);
    }

    /**
     * 字典类型删除数据
     *
     * @param id 字典类型ID
     */
    @DeleteMapping("/delete")
    public void deleteDictType(@Validated @NotBlank(message = "删除数据不能为空") @Size(max = 20, message = "ID最大长度不能超过20") String id) {
        service.deleteDictType(id);
    }

    /**
     * 字典类型启用、停用
     *
     * @param ao 请求参数
     */
    @PutMapping("/enable")
    public void enableDictType(@Validated @RequestBody DictTypeEnabledAO ao) {
        service.enableDictType(ao);
    }

}
